package com.aaron.messenger.data;

import java.io.DataOutputStream;
import java.io.IOException;

public class User {
	String name;
	String ip;
	String deviceinfo;
	UserState state;
	
	public enum UserState {
		UNKNOWN, ACTIVE, BUSY, LEAVE
	}
	
	public User() {
	}
	
	public User(String name, String ip, String deviceinfo, UserState state) {
		this.name = name;
		this.ip = ip;
		this.deviceinfo = deviceinfo;
		this.state = state;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getName() {
		return name;
	}
	
	public void setIp(String ip) {
		this.ip = ip;
	}
	
	public String getIp() {
		return ip;
	}
	
	public void setDeviceInfo(String deviceinfo) {
		this.deviceinfo = deviceinfo;
	}
	
	public String getDeviceInfo() {
		return deviceinfo;
	}
	
	public void setState(UserState state) {
		this.state = state;
	}
	
	public UserState getState() {
		return state;
	}
	
	@Override
	public boolean equals(Object user) {
		if(!(user instanceof User)) {
			return false;
		}
		return ip.equals(((User)user).getIp());
	}
	
	public void serialize(DataOutputStream out) throws IOException {
		out.write("User:".getBytes());
		out.write((name+":").getBytes());
		out.write((ip+":").getBytes());
		out.write((deviceinfo+":").getBytes());
	}
	
	public String toString() {
		return "Name:"+name+"  Ip:"+ip+"    Deviceinfo:"+deviceinfo+"    State:"+state;
	}
}
